package com.openfire.client.demo;

import java.io.IOException;
import java.util.concurrent.CyclicBarrier;

import org.jivesoftware.smack.ConnectionConfiguration.SecurityMode;
import org.jivesoftware.smack.tcp.XMPPTCPConnectionConfiguration;

import com.openfire.client.demo.job.UserConnectionJob;

/**
 * openfire client
 * 
 */
public class BatchUser_dev {
	public static void main(String[] args) throws InterruptedException, IOException {

		// 202.104.147.108 开发环境
		//String serviceName = "dev.qxclub.cn";
		String serviceName = "202.104.147.108";
		String password = "123456";
		XMPPTCPConnectionConfiguration configuration = XMPPTCPConnectionConfiguration.builder().setHost(serviceName)
				.setPort(5222).setServiceName(serviceName).setSecurityMode(SecurityMode.disabled)
				.setDebuggerEnabled(true)
				.setConnectTimeout(Integer.MAX_VALUE)
				.build();
		try {
			int userCount = 5000;
			CyclicBarrier barrier = new CyclicBarrier(userCount + 1);
			int count = 0;
			while (count < userCount) {
				String username = "batch_user_" + count;
				new Thread(new UserConnectionJob(username, password, configuration, barrier)).start();

				count++;
				Thread.sleep(20);
				System.out.println(count);
			}
			
			System.out.println("Done!");
			System.in.read();
			barrier.await();
			
		} catch (Exception e) {
			e.printStackTrace();
		} 
	}
}
